using System.ComponentModel.DataAnnotations;
using Core.Db.Dtos;

namespace Core.Db.ValidationAttributes;

public class TouristRouteTitleMustBeDifferentFromDescriptionAttribute : ValidationAttribute
{
    protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
    {
        var touristRouteDto = validationContext.ObjectInstance as TouristRouteForManipulationDto;
        if (touristRouteDto.Title.Equals(touristRouteDto.Description))
        {
            return new ValidationResult(
                "路线名称必须与路线描述不同",
                new[] { "TouristRouteForCreationDto" });
        }

        return ValidationResult.Success;
    }
}